<template>
    <div>

        <pageTable ref="table" :transform="mapFun" request-url="/api/advice/page" :columns="columns"
                   :request-param="{sStatus}" searchable>
            <Select placeholder="建议状态" clearable v-model="sStatus" style="width:200px" slot="search">
                <Option v-for="(v,k) in states" :value="k" :key="k">{{ v}}</Option>
            </Select>
        </pageTable>
        <advice v-model="adviceOpen" :order-id="curRow.orderId" :id="curRow.id" @ok="reload"></advice>
    </div>
</template>

<script type="text/jsx">
    import pageTable from "_c/page-table/page-table";
    import advice from "_c/advice-model/advice";

    export default {
        name: "advice-view",
        components: {
            pageTable, advice
        },

        data() {
            return {
                sStatus: null,
                states: {
                    0: "建议中",
                    1: "采纳",
                    2: "拒绝"
                },
                columns: [
                    {title: "维修建议id", key: "id"},
                    {title: "订单id", key: "orderId", width: 200},
                    {title: "工程师id", key: "engineerId", width: 200},
                    {title: "维修方案", key: "repairInfo", width: 150},
                    {title: "维修花费（元）", key: "cost", width: 150},
                    {
                        title: "建议状态",
                        width: 150,
                        notSearch: true,
                        render: (h, {row, index}) => {
                            let status = {
                                0: "processing",
                                1: "success",
                                2: "default"
                            }[row.sstatus]
                            return <Badge status={status} text={row.statusStr}/>
                        }
                    },
                    {
                        title: "操作",
                        notSearch: true,
                        render: (h, {row, index}) => {
                            let status = row.sstatus
                            if (status === 0) {
                                return (<Button type="primary" size="small" style="margin-right: 5px"
                                                on-click={this.openAdvice.bind(this, row)}>更新</Button>)
                            } else {
                                return <span>暂无</span>
                            }
                        }

                    }
                ],
                adviceOpen: false,
                finishOpen: false,
                curRow: {},
            };
        },
        methods: {
            reload() {
                this.$refs['table'].getTableData()
            },
            openAdvice(row = {}) {
                this.adviceOpen = !this.adviceOpen
                this.curRow = row
            },
            finishJob(row) {
                this.finishOpen = !this.finishOpen
            },
            mapFun(obj) {
                return {
                    ...obj,
                    statusStr: this.states[obj.sstatus]
                }
            }
        }
    };
</script>

<style scoped></style>
